package com.witmed.mymdm

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.lifecycle.lifecycleScope
import com.alibaba.android.arouter.launcher.ARouter
import com.tencent.mmkv.MMKV
import com.witmed.lib_base.BaseActivity
import com.witmed.mymdm.databinding.ActivitySlashBinding
import com.witmed.mymdm.mvi.SlashViewModel
import com.witmed.mymdm.mvi.WhiteUrlEntity
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class SlashActivity : BaseActivity<ActivitySlashBinding,SlashViewModel>() {
    override fun createVM(): SlashViewModel {
        return SlashViewModel()
    }

    override fun createV(): ActivitySlashBinding {
        return ActivitySlashBinding.inflate(layoutInflater)
    }

    override fun bindState() {
        lifecycleScope.launch {
            vm.mutableContainer.uiFlow.collect{
                if(it.lockState){
                    Toast.makeText(this@SlashActivity, "联系管理员解锁", Toast.LENGTH_SHORT).show()
                    finish()
                }else if(it.whiteState){
                    val list = ArrayList<WhiteUrlEntity>()
                    it.datas.forEach {
                        list.add(it)
                        Log.i("===",it.url)
                    }
                    val timer = async { delay(500) }
                    timer.await()
//            startActivity(Intent(this@SlashActivity,MainActivity::class.java))
                    ARouter.getInstance().build("/mdm/MainActivity").navigation()
                    finish()
                }
            }
        }
    }

    override fun initData() {
        vm.selWhite()
    }

    override fun initView() {

    }
}